<?php
include_once('./base/xcx_sqlclass.php');
include_once('./base/xcx_commonclass.php');
$fun=new commonfun();
$mysql=new MMsql();
$userid=$_POST['userid'];
$wkid=$userid."-".$fun->msecTime();
$stu_id=$userid.$fun->msecTime();
$stu_name=$_POST['tch_nickname'];
$stu_headimg=$_POST['tch_headimg'];

$arr=Array(
	"tch_headimg"     =>$_POST['tch_headimg'],
	"tch_nickname"	  =>$_POST['tch_nickname'],
	"tch_name"		  =>$_POST['tch_name'],
	"wk_id"           =>$wkid,
	"user_id"         =>$userid,
	"wk_className"    =>$_POST['classname'],
	"wk_classLevel"   =>$_POST['classlevel'],
	"wk_classNj"      =>$_POST['banji'],
	"wk_classKemu"    =>$_POST['kemu'],
	"wk_teacherPhone" =>$_POST['phonenum'],
	"wk_teacherNote"  =>$_POST['lsjianjie'],
	"wk_classNote"    =>$_POST['classnote'],
	"wk_classNoteImg" =>$_POST['classnoteimg'],
	"wk_classImg"     =>$_POST['classimg']
);
$data=$mysql->formatVal($arr);
$sql = "insert into wk_classinfo"."(".implode(',',array_keys($data)).") values(".implode(',',array_values($data)).")";
$type=1;//0-加入，1-创建
$sql2="insert into wk_students (user_id,wk_id,stu_name,stu_id,type) 
			values('".$userid."','".$wkid."','".$stu_name."','".$stu_id."','".$type."')";


try{
	$mysql->startTrans();
	$result=$mysql->doSql($sql);
	$result=$mysql->doSql($sql2);
	$result=$mysql->commit();
	if($result>0){
		// $data=$mysql
		$re=array(
				"status"=>200,
				"msg"   =>"创建成功！",
				"data"=>$arr				
			);
		echo json_encode($re);
	}
	
}catch(PDOException $e){
	$mysql->rollback();
	$re=array(
			"status"=>0,
			"msg"   =>"创建失败!"
		);
	echo json_encode($re);
}
